package com.wangyg.flourfactory.service.Impl;

import com.wangyg.flourfactory.dao.FlourFactoryRepository;
import com.wangyg.flourfactory.model.FlourFactory;
import com.wangyg.flourfactory.service.IFlourFactorySMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * Created by wangyg6 on 2019/5/15.
 */
@Service
public class FlourFactorySMOImpl implements IFlourFactorySMO {
	@Autowired
	FlourFactoryRepository repository;

	@Override
	public FlourFactory createFlourFactory(FlourFactory flourFactory) {
		return repository.save(flourFactory);
	}

	@Override
	public Integer getFlourCount(Integer factId) {
		Integer result = 1;
		FlourFactory factory = repository.findByFactId(factId);
		if (factory != null && factory.getFactId() != null) {
			result = new Random().nextInt(100);//生成一个介于0-100的随机数作为产量
		}
		return result;
	}
}
